//
//  NQUserInfo.m
//  ZLFastDoctor
//
//  Created by 李岚清 on 16/5/25.
//  Copyright © 2016年 LS. All rights reserved.
//

#import "NQUserInfo.h"

@implementation NQUserInfo

//创建模型类方法
+ (NQUserInfo *)userInfoWithIconImage:(UIImage *)iconImage name:(NSString *)name ID:(NSString *)ID iphone:(NSString *)iphone height:(NSString *)height weight:(NSString *)weight province:(NSString *)province{
    NQUserInfo *info = [[NQUserInfo alloc] init];
    info.iconImage = iconImage;
    info.name = name;
    info.ID = ID;
    info.iphone = iphone;
    info.height = height;
    info.weight = weight;
    info.province = province;
    return info;
}

//自定义归档/解档
- (void)encodeWithCoder:(NSCoder *)aCoder{
    [aCoder encodeObject:self.iconImage forKey:@"iconImage"];
    [aCoder encodeObject:self.name forKey:@"name"];
    [aCoder encodeObject:self.ID forKey:@"ID"];
    [aCoder encodeObject:self.iphone forKey:@"iphone"];
    [aCoder encodeObject:self.height forKey:@"height"];
    [aCoder encodeObject:self.weight forKey:@"weight"];
    [aCoder encodeObject:self.province forKey:@"province"];
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder{
    if (self = [super init]) {
        self.iconImage = [aDecoder decodeObjectForKey:@"iconImage"];
        self.name = [aDecoder decodeObjectForKey:@"name"];
        self.ID = [aDecoder decodeObjectForKey:@"ID"];
        self.iphone = [aDecoder decodeObjectForKey:@"iphone"];
        self.height = [aDecoder decodeObjectForKey:@"height"];
        self.weight = [aDecoder decodeObjectForKey:@"weight"];
        self.province = [aDecoder decodeObjectForKey:@"province"];
    }
    return self;
}

//归档/解档
+ (void)saveUserInfo:(NQUserInfo *)userInfo{
    //1.获取沙盒路径
    NSString *path = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES).lastObject;
    //2.拼接存储路径
    NSString *filePath = [path stringByAppendingPathComponent:@"userInfo.plist"];
    //3.归档
    [NSKeyedArchiver archiveRootObject:userInfo toFile:filePath];
}
+ (NQUserInfo *)readUserInfo{
    //1.获取沙盒路径
    NSString *path = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES).lastObject;
    //2.拼接存储路径
    NSString *filePath = [path stringByAppendingPathComponent:@"userInfo.plist"];
    //3.解档
    return [NSKeyedUnarchiver unarchiveObjectWithFile:filePath];
}

@end
